/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.class')
        .controller('ClassNoticeCreateCtrl', ClassNoticeCreateCtrl);

    function ClassNoticeCreateCtrl($scope,$stateParams,AppUtils,MsgModel,$state,LoginAccountAuth) {

        var vm = this;
        vm.notice = {};
        LoginAccountAuth.getAccount().then(function(data){
            vm.loginAccount = data;
            if(data.memberType === '1' && !AppUtils.isUndefinedOrNull(data.classId)){
                vm.notice.classId = data.classId;
            }else{
                AppUtils.showAlert("当前状态不可发布新公告！");
            }
        })


        $scope.commit = function(){
            if(AppUtils.isUndefinedOrNull(vm.notice.noticeTitle)){
                AppUtils.showTipsTop("请输入标题！");
                return false;
            }
            if(AppUtils.isUndefinedOrNull(vm.notice.noticeContent)){
                AppUtils.showTipsTop("请输入内容！");
                return false;
            }
            ClassNoticeModel.saveNoticePage(vm.notice).$promise.then(function(response){
                var result = response.result;
                if(!AppUtils.isUndefinedOrNull(result) && result == 'success'){
                    AppUtils.showAlert("发布成功！");
                    $state.go("classMenu.teacherIndex");
                }else{
                    AppUtils.showTipsTop("发布失败,请稍后再试！");
                }
            })
        }
    }
})();
